function publicTree(objClass,eId, eName, urlPath, stype, dblclickfn, viewPer ){
	this.objClass = objClass;
	this.eId = eId;
	this.eName = eName;
	this.urlPath = urlPath + '/loadtree';
	this.stype = stype;
	this.dblclickfn = dblclickfn;
	this.viewPer = viewPer;
}
publicTree.prototype.loadTreefrm = function(){		
	this.genTree();
	var objClass = this;
	$('input.clsearch').click(function(){
		objClass.adv_search($('#searchNode').attr('load'));
	});
	shortcut.add("Ctrl+K",function() {
		$('#searchNodes').focus();
		$('#searchNodes').select();
	});
	$('#searchNodes').focus(function() {
		shortcut.remove('Enter');		
	    shortcut.add("Enter",function() {
		 	objClass.adv_search($('#searchNode').attr('load'));
		});
	});
    //$("#loadTreeUrl").html("Hello World");
    // $('#searchNodes').focusout(function() {
	// 	shortcut.remove('Enter');
	// 	shortcut.add("Enter",function() {
	// 		objClass.objClass.ldmod();
	// 	});		
	// });
}
publicTree.prototype.genTree = function(){		
	var objClass = this;
	// alert(objClass.viewPer);	
	var self = this
		,url = this.urlPath
		,arrDataTree = [];	
	switch(self.stype){
		case 'TRAINING':
			arrDataTree = $.parseJSON(dataTreeTranning);
			arrNodeDefault = $.parseJSON(nodeDefaultTraining);
			break;
		case 'LEARNING':
			arrDataTree = $.parseJSON(dataTreeLearning);
			arrNodeDefault = $.parseJSON(nodeDefaultLearning);
			// alert(arrNodeDefault);
			break;
	}

	obj = $("#left_tree");
	obj.jstree({ 
		"plugins" : [ 
			"themes","json_data","ui","crrm","dnd","search","adv_search","types","hotkeys",""
		],	
		"json_data" : { 
			"data" : arrDataTree
		},
		"core" : { 
			"initially_open" : arrNodeDefault 
		},
	 	"themes" : {
	            "theme" : "default",
	            "dots" : false,
	            "icons" : true,
	            "url": baseUrl + '/public/efy-js/jsTree/themes/default/style.css'
	    		}	    		
	})
	/*.bind("loaded.jstree", function (event, data) {
		 $("#searchNode").click(function () {
		 	$( "#left_tree").jstree('close_all', -1);
		 	$("#left_tree").jstree("search", $('#searchNodes').val());
		 	 $("#left_tree").jstree("refresh");
		});
		 $('#searchNodes').focus(function() {
			shortcut.remove('Enter');
			shortcut.add("Enter",function() {
		 		$("#left_tree").jstree('close_all', -1);
					$("#left_tree").jstree("search", $('#searchNodes').val());
			 	 	$("#left_tree").jstree("refresh");
			});
			// document.onkeydown =function(e){
			// 	if(e.which == 13){
			// 		$("#left_tree").jstree('close_all', -1);
			// 		$("#left_tree").jstree("search", $('#searchNodes').val());
			//  	 	$("#left_tree").jstree("refresh");
			// 	}
			// }
		});	
		// $('#searchNodes').focusout(function() {
		// 	shortcut.remove('Enter');		
		// });	
		$("#searchNode").trigger('click');
		$("#searchNode").trigger('focus');
		// $("#searchNode").trigger('focusout');

	})	*/
	.bind("select_node.jstree", function (event, data) { 
			if(data.rslt.obj.attr("id") != ''){
				$('#type').attr('checked',false);
			}
			$('#selectValueTrainingTree').val(data.rslt.obj.attr("id"));
			objcurent = data.rslt.obj;			
			objNode = data.inst._get_node(data.rslt.obj.attr("id"));
			resulter = data.inst._get_node(data.rslt.obj);
            obj.jstree("toggle_node", data.rslt.obj);  
            objClass.eId.val(data.rslt.obj.attr("id"));
            objClass.eName.val(data.inst.get_text(data.rslt.obj));
		})
	.delegate("a.jstree-clicked", "click", function (event, data) { 
			event.preventDefault(); 
    })
	.delegate("a","dblclick", function(e) { 	
		objClass.eId.val($(this).parent().attr("id"));
		objClass.eName.val($.trim($(this).text()));
		switch(objClass.dblclickfn){
			case "comment":
				objClass.objClass.ldmodcmmt();
				break;
			case "approve":
				objClass.objClass.ldmodapprove();
				break;
			default:
				objClass.objClass.ldmod();
		}
	});
}
publicTree.prototype.adv_search = function(a){
	$("#left_tree").jstree("search", $('#searchNodes').val());
	/*var objClass = this;
	var searchNodes = $('#searchNodes').val();
	if(searchNodes != ''){
		alert(222);
		var url = this.urlPath + '/loadtree';
		var data = {searchNodes : searchNodes, sType: objClass.stype, viewPer: objClass.viewPer}
		if(a == 'true'){
			$.ajax({
				url:url,
				type:"POST",
				data:data,
				dataType: "json",				
				success: function(arrDataTree){
					$('#searchNode').attr('load',false);
					var searchNodes = $('#searchNodes').val();
					var arrParamTree  = ['PK_OBJECT','FK_OBJECT','TR04','C_HAVE_CHILDREN'];
					$('#left_tree').html(objClass.creatTree(arrDataTree, arrParamTree));	
					objClass.genTreeSearch($('#left_tree'));
				}
			});
		}
		else{
			$("#left_tree").jstree("search", $('#searchNodes').val());
		 	// $("#left_tree").jstree("refresh");
			// $("#left_tree").jstree("refresh"); 
			
		}  
	}else{
		$('#searchNodes').focus();
	}*/
}
publicTree.prototype.creatTree = function(data, param){
	var arrParent = [];
	var lenData   = data.length;
	var htmlOut   = '<ul>'
	var parentTem = '';
	for(var i = 0; i < lenData; i++){	
		parentTem = data[i][param[1]];
		if(arrParent != '')
			for(var j = (arrParent.length - 1); j >= 0; j--)
				if(parentTem != arrParent[j]){	
					arrParent.splice(j,1);	
					htmlOut += '</ul></li>';	
				}else	break;
		htmlOut += '<li id = "'+data[i][param[0]]+'">'+ '<a href="#">'+data[i][param[2]]+'</a>';
		if(data[i][param[3]] == 1){
			arrParent.push(data[i][param[0]]);
			htmlOut += '<ul>';	
		}	
	}	
	return htmlOut;
}

publicTree.prototype.genTreeSearch = function(){
	var objClass = this;	
	var url = this.urlPath + '/loadtree'
		,arrNodeDefault = this.arrNodeDefault;
	obj = $("#left_tree");
	obj.jstree({ 
		"plugins" : [ 
			"themes","html_data","ui","crrm","dnd","search","types","hotkeys",""
		],	
		"json_data" : { 
			"ajax" : {
				"url" : url,
				"data" : function (n) { 
					return { 
						"operation" : "get_children", 
						"id" : n.attr ? n.attr("id").replace("node_","") : '',
						"sType":objClass.stype,
						"viewPer": objClass.viewPer
					};

				},
				"success": function(data){
					
				}
			}
		},
		"core" : { 
			"initially_open" : arrNodeDefault 
		},
	 	"themes" : {
	            "theme" : "default",
	            "dots" : false,
	            "icons" : true,
	            "url": baseUrl + '/public/efy-js/jsTree/themes/default/style.css'
	    		}
	})		
	.bind("loaded.jstree", function (event, data) {
		 $("#searchNode").click(function () {
		 	$( "#left_tree").jstree('close_all', -1);
		 	$("#left_tree").jstree("search", $('#searchNodes').val());
		 	 $("#left_tree").jstree("refresh");
		});
		 $('#searchNodes').focus(function() {
			shortcut.remove('Enter');
			shortcut.add("Enter",function() {
		 		$("#left_tree").jstree('close_all', -1);
					$("#left_tree").jstree("search", $('#searchNodes').val());
			 	 	$("#left_tree").jstree("refresh");
			});
			// document.onkeydown =function(e){
			// 	if(e.which == 13){
			// 		$("#left_tree").jstree('close_all', -1);
			// 		$("#left_tree").jstree("search", $('#searchNodes').val());
			//  	 	$("#left_tree").jstree("refresh");
			// 	}
			// }
		});	
		// $('#searchNodes').focusout(function() {
		// 	shortcut.remove('Enter');		
		// });	
		// $("#searchNode").trigger('click');
		$("#searchNode").trigger('focus');
		// $("#searchNode").trigger('focusout');

	})
	.bind("select_node.jstree", function (event, data) {
			if(data.rslt.obj.attr("id") != ''){
				$('#type').attr('checked',false);
			} 
			$('#selectValueTrainingTree').val(data.rslt.obj.attr("id"));
			objcurent = data.rslt.obj;			
			objNode = data.inst._get_node(data.rslt.obj.attr("id"));
			resulter = data.inst._get_node(data.rslt.obj);
            obj.jstree("toggle_node", data.rslt.obj);  
            objClass.eId.val(data.rslt.obj.attr("id"));
			objClass.eName.val(data.inst.get_text(data.rslt.obj));
		})
	.delegate("a.jstree-clicked", "click", function (event, data) { 
			event.preventDefault(); 
		})
	.delegate("a","dblclick", function(e) { 	
		objClass.eId.val($(this).parent().attr("id"));
		objClass.eName.val($.trim($(this).text()));
		objClass.objClass.ldmod();
	});
}